package com.biz.primus.ms.promotion.dao.redis;

import com.biz.primus.ms.promotion.dao.ro.PresellPromotionRo;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

/**
 * 预售活动Redis Dao
 *
 * @author david-liu
 */
@Repository
public class PresellPromotionRedisDao extends BasePromotionRedisDao<PresellPromotionRo, Long> {

    /**
     * 获取系统中所有可用的预售活动
     *
     * @return 预售活动
     */
    public List<PresellPromotionRo> getPresellPromtoions() {
        List<PresellPromotionRo> presellPromotionRos = super.findAll();
        if (CollectionUtils.isEmpty(presellPromotionRos)) {
            return Collections.emptyList();
        } else {
            return presellPromotionRos;
        }
    }

    /**
     * 批量获取秒杀活动商品信息
     *
     * @param promotionIds 秒杀活动ID集合
     * @return 商品集合
     */
    public Map<Long, List<Long>> getPromotionProducts(List<Long> promotionIds) {
        return super.getPromotionProducts(promotionIds, this::getPresellPromotionProductSortedSetKey);
    }


    /**
     * 获取预售活动商品SortedSet Key
     *
     * @param promotionId 活动ID
     * @return SortedSet Key
     */
    private String getPresellPromotionProductSortedSetKey(Long promotionId) {
        return getKeyByParams(promotionId, "prds");
    }

}
